<?php

namespace Xrfg\Api\Consume\Observers;

use Carbon\Carbon;
use Xrfg\Core\Common\Services\Proof;
use Xrfg\Api\Consume\Models\ConsumeAccounts;
use Xrfg\Api\Consume\Models\ConsumeAccountLog;

class ConsumeAccountObserver
{
    public function updated(ConsumeAccounts $account)
    {
        if ($account->availableChange) {
            ConsumeAccountLog::create([
                'user_id' => $account->user_id,
                'coin_id' => $account->coin_id,
                'type' => $account->type,
                'account_type' => 'available',
                'action_id' => $account->action_id,
                'before' => $account->getOriginal('available'),
                'number' => $account->availableChange,
                'after' => $account->available,
                'version' => $account->version,
                'time' => Carbon::now()
            ]);
        }

        if ($account->disabledChange) {

            ConsumeAccountLog::create([
                'user_id' => $account->user_id,
                'coin_id' => $account->coin_id,
                'type' => $account->type,
                'account_type' => 'disabled',
                'action_id' => $account->action_id,
                'before' => $account->getOriginal('disabled'),
                'number' => $account->disabledChange,
                'after' => $account->disabled,
                'version' => $account->version,
                'time' => Carbon::now()
            ]);
        }

        if ($account->freezeChange) {
            ConsumeAccountLog::create([
                'user_id' => $account->user_id,
                'coin_id' => $account->coin_id,
                'type' => $account->type,
                'account_type' => 'freeze',
                'action_id' => $account->action_id,
                'before' => $account->getOriginal('freeze'),
                'number' => $account->freezeChange,
                'after' => $account->freeze,
                'version' => $account->version,
                'time' => Carbon::now()
            ]);
        }
    }
}
